package com.woniuxy.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
    public static String getMd5(String source) {
        try {
            //创建加密的核心对象，指定MD5加密算法
            MessageDigest digest = MessageDigest.getInstance("MD5");
            //密码加密
            byte[] bytes = digest.digest(source.getBytes());
            //将结果转成32位标准字符串
            StringBuilder builder = new StringBuilder();
            for (byte b : bytes) {
                builder.append(String.format("%02X", b));
            }
            return builder.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
